<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="btn">11</div>

    <script>
        let btn = document.getElementById('btn');
        console.log('===>btn', btn);
        // 功能：实现html模块的复用
        //  复制代码
        var buttonJson = [{
            "btnClass": "btn-default",//按钮样式：默认
            "isClose": true,//点击是否关闭：关闭
            "text": "取消",//：按钮内容
            "tOrF": true, //点击返回true(针对confirm)
            "isClose": false,//点击是否关闭：不关闭
            "text": "确定"
        }];
        var ttl = "删除11";// 标题
        var cont = "是否要删除此条历史记录";// 显示内容
        var isTrueNum = 0;//0弹窗弹出；1点击确定；2点击取消
        var confirm_ClickObject;

        //弹窗设定
        function showWindow(ttl, cont, buttonJson, returnObject) {
            if (returnObject != undefined && returnObject != null) {
                confirm_ClickObject = returnObject;
            }
            if (isTrueNum == 1) {
                isTrueNum = 0;
                return true;
            } else if (isTrueNum == 2) {
                isTrueNum = 0;
                return false;
            } else {
                //弹窗的样式
            }

        }
        function callback_OK() {
            isTrueNum = 1;
            if ($(confirm_ClickObject).attr("onclick") != undefined && $(confirm_ClickObject).attr("onclick").length > 0) {
                $(confirm_ClickObject).click();
            } else if ($(confirm_ClickObject).attr("onchange") != undefined && $(confirm_ClickObject).attr("onchange").length > 0) {
                $(confirm_ClickObject).change();
            } else {
                $(confirm_ClickObject).click();
            }
        }
        function callback_QU() {
            isTrueNum = 2;
            if ($(confirm_ClickObject).attr("onclick") != undefined && $(confirm_ClickObject).attr("onclick").length > 0) {
                $(confirm_ClickObject).click();
            } else if ($(confirm_ClickObject).attr("onchange") != undefined && $(confirm_ClickObject).attr("onchange").length > 0) {
                $(confirm_ClickObject).change();
            } else {
                $(confirm_ClickObject).click();
            }
        }
        //重写alert
        window.alert = function newAlert(cont) {
            var ttl = "11111111111";
            var buttonJson = [{
                "btnClass": "btn-primary",
                "isClose": true,
                "text": "确定"
            }];

            showWindow(ttl, cont, buttonJson);
        };
        //重写confirm
        window.confirm = function newConfirm(obj, cont) {
            console.log('===>22',);
            var ttl = "11111111121";
            var buttonJson = [{
                "btnClass": "btn-default",
                "isClose": true,
                "text": "取消",
                "tOrF": false
            }, {
                "btnClass": "btn-primary",
                "isClose": true,
                "text": "确定",
                "tOrF": true
            }];
            return showWindow(ttl, cont, buttonJson, obj);
        };
        //写返回的alert
        function alert1(obj, cont) {
            var ttl = "温馨提示";
            var buttonJson = [{
                "btnClass": "btn-primary",
                "isClose": true,
                "text": "确定",
                "tOrF": true
            }];
            return showWindow(ttl, cont, buttonJson, obj);
        }
        btn.addEventListener('click', () => {
            console.log('===>qqq',);
            window.confirm(ttl, cont, buttonJson, confirm_ClickObject)
        })
    </script>


</body>

</html>